<%--
  Created by IntelliJ IDEA.
  User: zhangkeke
  Date: 2022/10/12
  Time: 14:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>转账</title>
  <script src="${pageContext.request.contextPath}/jcript/jquery-1.7.2.js"></script>
    <script>
        $(function (){
            $("#code_img").click(function (){
                this.src="http://localhost:8087/kaptcha.jpg"
            })
            $("#select").change(function (){
                var select = $("#select").val()
                $.ajax({
                    url:"/query",
                    data:{id_card:select},
                    dataType:"json",
                    success:function (data){
                        $("#sp").text("该卡里还有余额："+data+"元")
                    }

                })
            })
            $("span").css({"display":"inline-block","width":"150px","text-align":"right"})
            $("#btn").click(function (){
                var name = $("#inp1").val();
                var card_no = $("#inp2").val();
                var bank = $("#inp3").val();
                var money = $("#inp4").val();
                var code = $("#code").val();
                var id_card = $("#select").val();
                var payment_pwd = $("#inp5").val();
                $.ajax({
                    url:"/transferMoney",
                    data:{name:name,card_no:card_no,bank:bank,money:money,code:code,id_card:id_card,payment_pwd:payment_pwd},
                    dataType:"json",
                    success:function (data){
                        if(data==0){
                            $("#sp").text("得到新转账账号，并转账成功")
                            var flag = confirm("是否回到首页，点击确定回到首页，取消继续转账")
                            if(flag){
                                location.href="/pages/userMenu.jsp"
                            }else {
                                location.href="/pages/card/transfer_accounts.jsp"
                            }
                        }else if(data==2){
                            $("#sp").text("转账失败，验证码、姓名或者支付密码输入错误，请重新输入")
                        }
                        else {
                            $("#sp").text("转账成功")
                            var flag = confirm("转账成功，是否回到首页，点击确定回到首页，取消继续转账")
                            if(flag){
                                location.href="/pages/userMenu.jsp"
                            }else {
                                location.href="/pages/card/transfer_accounts.jsp"
                            }
                        }
                    }
                })
            })
        })
    </script>
</head>
<body>
<div style="position: relative;left: 400px;top: 150px">
    <h3>转账</h3>
    <span>收款人姓名:</span><input type="text" id="inp1" name="name" placeholder="输入收款人姓名" required><br><br>
    <span>收款人账号:</span><input type="text" id="inp2" name="card_no" placeholder="输入收款人账号" required><br><br>
    <span>收款人开户行:</span><input type="text" id="inp3" name="bank" placeholder="输入收款人开户银行" required><br><br>

    <span>选择付款账号:</span>
    <select id="select">
        <option selected="selected">请选择银行卡</option>
        <c:forEach items="${account}" var="card">
            <option value="${card.id_card}">${card.id_card}</option>
        </c:forEach>
    </select><span id="sp" style="color: red;font-size: 3px"></span><br><br>


    <span>转账金额</span><input type="text" id="inp4" name="money" placeholder="输入要转账的金额" required><br>
    <span>验证码</span><input type="text" id="code" name="code" required><img src="http://localhost:8087/kaptcha.jpg" id="code_img"><br>

    <span>支付密码</span><input type="password" placeholder="请输入支付密码" id="inp5" name="payPwd">


    <button id="btn">确定转账</button>
    <a href="/pages/userMenu.jsp">返回首页</a>
</div>



</body>
</html>
